package com.epsilon.pos.principal.delegate;

import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;

import com.epsilon.pos.principal.ventas.delegator.VentasPrincipalControl;
import com.epsilon.pos.principal.view.PrincipalPosShell;

public class PrincipalPosEventDelegate {

	private static final int		_INDEX_TAB_VENTAS_	= 0;

	private EventoClickTbFolder		eventoClickTbFolder;
	private VentasPrincipalControl	ventasPrincipalControl;

	private PrincipalPosShell		shell;
	private CTabFolder				cTabFolderPrincipal;

	public PrincipalPosEventDelegate( PrincipalPosShell principalShell ) {
		shell = principalShell;
		cTabFolderPrincipal = shell.getCTfPrincipal();
		eventoClickTbFolder = new EventoClickTbFolder();
	}

	private class EventoClickTbFolder implements SelectionListener {
		@Override
		public void widgetSelected( SelectionEvent arg0 ) {
			CTabItem ctiVentas = cTabFolderPrincipal.getItem( _INDEX_TAB_VENTAS_ );

			if( cTabFolderPrincipal.getSelection().hashCode() == ctiVentas.hashCode() ) {
				ventasPrincipalControl.refreshVentasPrincipal();
				ventasPrincipalControl.getVentasPrincipalComposite().getTxtCodigo().setFocus();
			}
		}

		@Override
		public void widgetDefaultSelected( SelectionEvent arg0 ) {
		}
	}

	public EventoClickTbFolder getEventoFocusVentasPrincipal() {
		return eventoClickTbFolder;
	}

	public void setVentasPrincipalControl( VentasPrincipalControl ventasPrincipalControl ) {
		this.ventasPrincipalControl = ventasPrincipalControl;
	}
}